#include"common.hpp"

#define LOG_TAG "driver_common"
#define LOG_LVL LOG_LVL_DBG
#include <ulog.h>

robot_driver::robot_driver(const char* name)
{
    rt_strncpy(this->name, name, rt_strnlen(name, 10)+1);
    hw_handle = rt_device_find(this->name);
    if(hw_handle==RT_NULL)
    {
        LOG_W("can't find device %s", this->name);        
    }
}

robot_driver::~robot_driver()
{
    if(hw_handle!=RT_NULL)
        rt_device_close(hw_handle); 
}

int robot_driver::write(int pos, const void *buffer,int size)
{
    return rt_device_write(this->hw_handle, 0, buffer, size);
}

int robot_driver::read(int pos, void *buffer,int size)
{
    return rt_device_read(this->hw_handle, 0, buffer, size);
}